#include <iostream>
#include <opencv2/core/core.hpp>
#include <opencv2/opencv.hpp>
#include <opencv2/highgui/highgui.hpp>
#include "opencv2/imgproc/imgproc.hpp"

using namespace cv;
using namespace std;

int main()
{
	VideoCapture capture(0);
	if (!capture.isOpened()) { //判断能够打开摄像头
		cout<<"can not open the camera"<<endl;
		cin.get();
		exit(1);
	}

	capture.set(CV_CAP_PROP_FRAME_WIDTH, 1280);
	capture.set(CV_CAP_PROP_FRAME_HEIGHT, 720);

	int count=0;

	while (1) {
		Mat frame;
		capture>>frame; //载入图像

		if (frame.empty()) { //判断图像是否载入
			cout<<"can not load the frame"<<endl;
		} else {
			count++;
			if (count == 1) {
				cout<<frame.cols<<"  "<<frame.rows<<endl;
			}

			imshow("camera", frame);
			char c=waitKey(30); //延时30毫秒
			if (c == 27) //按ESC键退出
				break;
		}
	}
}